package org.cpoy.ei.session;

import org.cpoy.eims.entity.Parent;
import org.cpoy.eims.entity.Student;
import org.cpoy.eims.entity.StudentAdmission;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("studentAdmissionHome")
public class StudentAdmissionHome extends EntityHome<StudentAdmission> {

	@In(create = true)
	ParentHome parentHome;
	@In(create = true)
	StudentHome studentHome;

	public void setStudentAdmissionId(Integer id) {
		setId(id);
	}

	public Integer getStudentAdmissionId() {
		return (Integer) getId();
	}

	@Override
	protected StudentAdmission createInstance() {
		StudentAdmission studentAdmission = new StudentAdmission();
		return studentAdmission;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Student student = studentHome.getDefinedInstance();
		if (student != null) {
			getInstance().setStudent(student);
		}
		Parent parent = parentHome.getDefinedInstance();
		if (parent != null) {
			getInstance().setParent(parent);
		}
	}

	public boolean isWired() {
		if (getInstance().getStudent() == null)
			return false;
		if (getInstance().getParent() == null)
			return false;
		return true;
	}

	public StudentAdmission getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}


}
